package code08_三大特征;

public class Test07_构造方法的调用过程 {
	public static void main(String[] args) {
		Pig pig = new Pig("佩琪", "女", 3, 18.6);
		pig.print();
	}
}

/*
 * 父父类
 */
class Live {
	public Live() {
		System.out.println("父父类Live中无参的构造方法....");
	}
}

/*
 * 父类
 */
class Animal extends Live {
	String name;
	String sex;

	public Animal() {
		super();
		System.out.println("父类Animal中无参的构造方法.......");
	}

	public Animal(String name, String sex) {
		this.name = name;
		this.sex = sex;
		System.out.println("父类Animal中带参的构造方法.......");
	}

	public void show() {
		System.out.println("父类中的show方法......");
	}

}

/*
 * 子类
 */
class Pig extends Animal {
	int age;
	double weight;

	String name = "乔治"; // 子类和父类中，出现了同名的属性

	public Pig() {
		super(); // 子类构造方法中默认隐含着super()，表示调用父类中无参的构造方法
		System.out.println("子类Pig中无参的构造方法.......");
	}

	public Pig(int age, double weight) {
		this.age = age;
		this.weight = weight;
		System.out.println("子类Pig中带两个参数的构造方法.......");
	}

	public Pig(String name, String sex, int age, double weight) {
		super(name, sex); // 调用父类中带参的构造方法，必须位于第一条语句
		// this(age,weight); // 调用当前类中带参的构造方法，必须位于第一条语句
		// this.name = name;
		// this.sex = sex;
		this.age = age;
		this.weight = weight;
		System.out.println("子类Pig中带四个参数的构造方法.......");
	}

	public void print() {
		String name = "旺财";

		System.out.println("局部变量姓名：" + name);
		System.out.println("子类中的姓名：" + this.name);
		System.out.println("父类中的姓名：" + super.name); // 使用super调用父类中的属性
		System.out.println("性别：" + sex);
		System.out.println("性别：" + this.sex);
		System.out.println("性别：" + super.sex);
		System.out.println("年龄：" + age);
		System.out.println("体重：" + weight);
	}
}
